package com.kang.controller;

import com.kang.entity.Concern;
import com.kang.service.ConcernService;
import com.kang.util.WebResponse;
import com.kang.vo.ParamInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "关注接口")
@RequestMapping("/user/concern")
@Slf4j
public class ConcernController {

    @Autowired
    private ConcernService concernService;

    @ApiOperation("关注")
    @PostMapping("insertConcern")
    public WebResponse insertConcern(@RequestBody Concern concern) {
        try {
            return WebResponse.resSuccess("关注成功",concernService.insertConcern(concern));
        } catch (Exception ex) {
            log.error("关注失败");
            return WebResponse.resFail("关注失败",null);
        }

    }

    @ApiOperation("取消关注")
    @PostMapping("deleteConcern")
    public WebResponse deleteConcern(@RequestBody Concern concern) {
        try {
            return WebResponse.resSuccess("取消关注成功",concernService.deleteConcern(concern.getConcernId()));
        } catch (Exception ex) {
            log.error("取消关注失败");
            return WebResponse.resFail("取消关注失败",null);
        }

    }


    /**
     * 前端取集合长度
     * @return
     */
    @ApiOperation("获取关注人数以及关注列表")
    @GetMapping("getConcernCount")
    public WebResponse getConcernCount(ParamInfo paramInfo) {
        try {
            return WebResponse.resSuccess("获取关注人数成功",concernService.getConcernCount(paramInfo));
        } catch (Exception ex) {
            log.error("获取关注人数失败");
            return WebResponse.resFail("获取关注人数失败",null);
        }

    }


    /**
     * 前端取集合长度
     * @return
     */
    @ApiOperation("获取粉丝人数以及粉丝列表")
    @GetMapping("getFenSiCount")
    public WebResponse getFenSiCount(ParamInfo paramInfo) {
        try {
            return WebResponse.resSuccess("获取粉丝人数以及粉丝列表成功",concernService.getFenSiCount(paramInfo));
        } catch (Exception ex) {
            log.error("获取粉丝人数以及粉丝列表失败");
            return WebResponse.resFail("获取粉丝人数以及粉丝列表失败",null);
        }

    }
}
